def b(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def a(num):
    c = 0
    while True:
        if b(num + c):
            return num + c
        elif b(num - c):
            return num - c
        c += 1

t = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}

try:
    w = input().split()
    if len(w) != 3:
        raise ValueError
    num = int(''.join(str(t[x]) for x in w))
    print(a(num))
except (KeyError, ValueError):
    print("Wrong input")


